<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
	<button type="button" class="layui-btn" id="test1">
		<i class="layui-icon">&#xe67c;</i>上传图片
	</button>

	<script src="layui/layui.js"></script>
	<script type="text/javascript">
	layui.use('upload', function(){
		  var upload = layui.upload;
		  var $ = layui.$;
		  //执行实例
		  var uploadInst = upload.render({
			accept: 'file'
		    ,elem: '#test1' //绑定元素
		    ,url: './uploadFile' //上传接口
		    ,done: function(res,index,upload){
		      //上传完毕回调
		    	   if(res.status == 1){
		    		      //do something （比如将res返回的图片链接保存到表单的隐藏域）
		    		      alert("上传成功！");
		    		    }
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });
		});
	</script>
</body>
</html>